﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LazyKex.Semantic
{
    public class CodeGenerator
    {

        private StringBuilder codeBuilder = new StringBuilder();
        private StringBuilder tailBuilder = new StringBuilder();

        public CodeGenerator()
        {
            codeBuilder.AppendLine(@"
void entra(char c);
void novo_escopo();
void fecha_escopo();
void imprime();
void tenta_reduzir();

// função principal
int main() {
	novo_escopo();");

            tailBuilder.AppendLine(@"imprime();
}");


        }


        public string GetCode()
        {
            return codeBuilder.ToString() + tailBuilder.ToString();
        }

        public void GenerateEnterChar(char c)
        {
            codeBuilder.AppendLine("entra('" + c.ToString().ToUpperInvariant()+ "'); tenta_reduzir();");
        }

        public void GenerateNewEscope()
        {
            codeBuilder.AppendLine("novo_escopo();");
        }

        public void GenerateEndEscope()
        {
            codeBuilder.AppendLine("fecha_escopo(); tenta_reduzir();");
        }

    }
}
